package com.zhou.jiancai.activity;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.github.sumimakito.awesomeqr.AwesomeQRCode;
import com.zhou.jiancai.R;
import com.zhou.jiancai.base.BaseActivity;

/**
 * Created by Administrator on 2017/5/16.
 */

public class QRcodeActivity extends BaseActivity {


    ImageView image1;

    ImageView image2;

    ImageView image3;
    private Bitmap qrCodeWithBackground;
    private Bitmap backgroundBitmap;
    private Bitmap logoBitmap;
    private EditText editText;

    @Override
    protected void initdata() {

    }

    @Override
    protected void initview() {
    /*    Bitmap qrCode = AwesomeQRCode.create("Makito lafuu Chino.", 800, 20);
        image1= (ImageView) findViewById(R.id.image1);

        image1.setImageBitmap(qrCode);*/
        image2= (ImageView) findViewById(R.id.image2);
        editText = (EditText) findViewById(R.id.edit);
        SaveNewContent();


      Button button=  (Button)findViewById(R.id.bt_save);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SaveNewContent();
            }
        });

      /*  Bitmap logoBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.abc);
        Bitmap qrCodeWithLogo = AwesomeQRCode.create("Makito loves Kafuu Chino.", 800, 20,logoBitmap,true,true);
        image3= (ImageView) findViewById(R.id.image3);
        image3.setImageBitmap(qrCodeWithLogo);*/

       // Bitmap qrCodeWithBackgroundAndLogo = AwesomeQRCode.create("Makito loves Kafuu Chino.", 800, 20, backgroundBitmap, logoBitmap);

    }

    private void SaveNewContent() {


        String text= editText.getText().toString();
        if (text==null){
            text="周志学";

        }
        backgroundBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.timg4);
        logoBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.zzx);
  /*      new Thread(new Runnable() {
            @Override
            public void run() {
               // qrCodeWithBackground = AwesomeQRCode.create("周志学", 800, 20,0.3f, Color.BLACK,Color.WHITE, backgroundBitmap,false,false,false,128,false,logoBitmap,10,8,10);

            }
        }).start();*/
        Bitmap qrCodeWithBackground =   AwesomeQRCode.create(text, 800, 20,0.3f, Color.BLACK,Color.WHITE,backgroundBitmap,false,false,false,128,false,logoBitmap,10,8,10);
        // Bitmap qrCodeWithBackground = AwesomeQRCode.create("周志学", 800, 20,0.3F,100000,-100000,backgroundBitmap,true,true,true);
        image2.setImageBitmap(qrCodeWithBackground);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_qrcode;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }
}
